<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="copyright" content="www.infoearth.com" />
		<title>群测群防数据采集系统</title>
		<link rel="stylesheet" href="../css/api.css">
		<link rel="stylesheet" href="../css/base.css">
		<link rel="stylesheet" type="text/css" href="../css/api.css"/>
		<link rel="stylesheet" href="../lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.css">
		<script src="../lib/jquery.mobile-1.4.5/jquery.min.js"></script>
		<script src="../lib/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.js"></script>
		<script type="text/javascript" src="../script/api.js"></script>
		<script src="../lib/config.js"></script>
		<script src="../lib/common.js"></script>
	</head>
	<body>
		<div id="wrap">
			<header id='header'>
				<nav id="nav">
					<a id="left" onclick="api.closeWin();"> <span>返回</span> </a>
					<div id="middle">
						<strong id="title">新增监测点</strong>
					</div>
					<a class="rightSave" id="btnSave"><span>保存</span></a>
				</nav>
			</header>
			<div id="main">
				<div style="margin: 0px 15px;padding-top: 10px">
					<div style="margin: 10px 0px;">
						<label for="tbPntName">监测点名称：</label>
						<input type="text" name="tbPntName"  id="tbPntName" >
					</div>
					<div style="margin: 10px 0px;">
						<label for="combType">监测类型：</label>
						<select name="combType" id="combType">
							<option value="DL">地缝缝宽</option>
							<option value="QL">墙裂缝宽</option>
							<option value="DG">地鼓</option>
							<option value="JS">井水</option>
							<option value="QS">泉水</option>
						</select>
					</div>
					<div style="margin: 15px 0px;">
						<label for="tbLocation">监测位置：</label>
						<input type="text" name="tbLocation"  id="tbLocation" >
					</div>
					<div style="margin: 10px 0px;">
						<label for="tbLon">经度：</label>
						<input type="text" name="tbLon"   id="tbLon" >
					</div>
					<div style="margin: 10px 0px;">
						<label for="tbLat">纬度：</label>
						<input type="text" name="tbLat"   id="tbLat" >
					</div>
					<div style="margin: 10px 0px;">
						<label for="tbDes">备注：</label>
						<textarea name="tbDes" id="tbDes" rows="8" cols="40"></textarea>
					</div>
				</div>
			</div>
		</div>
		<script>
			var hazardInfo = null;
			var position = null;
			apiready = function() {
				api.addEventListener({
					name : 'keyback'
				}, function(ret, err) {
					api.closeWin();
				});
				hazardInfo = getCookie('hazardInfo');
//				showMsg("hazardInfo" + hazardInfo);
				hazardInfo = JSON.parse(hazardInfo);
				//获取设备所处位置
				api.getLocation(function(ret, err) {
					if (ret.status) {
						position = ret;
						if (position != null) {
							$("#tbLon").val(position.longitude);
							$("#tbLat").val(position.latitude);
						}
					}
				});
				$("#btnSave").click(function() {
					saveRecord();
				});
			};
			function getSelMonitorType() {
				var typeName = $("#combType  option:selected").text();
				// showMsg("getSelMonitorType(),类型" + typeName);
				var typeCode = 'NO';
				switch(typeName) {
					case '地鼓':
						typeCode = 'DG';
						break;
					case'地缝缝宽':
						typeCode = 'DL';
						break;
					case '墙裂缝宽':
						typeCode = 'QL';
						break;
					case '井水':
						typeCode = 'JS';
						break;
					case '泉水':
						typeCode = 'QS';
						break;
					default:
//						typeCode = typeName;
						break;
				}
				return typeCode;
			}

			function saveRecord() {
				Guid2(function(res) {
					var item = {
						"QCQFJCD01010" : res,
						//						"QCQFJCD01020" : hazardInfo.QCQFD01010,
						"QCQFJCD01020" : hazardInfo.JBQK0100,
						"QCQFJCD01030" : getSelMonitorType(),
						"QCQFJCD01040" : $("#tbLon").val(),
						"QCQFJCD01050" : $("#tbLat").val(),
						"QCQFJCD01060" : $("#tbLocation").val(),
						"QCQFJCD01070" : $("#tbPntName").val(),
						"QCQFJCD01080" : $("#tbDes").val()
					};
					if (item.QCQFJCD01070 == '' || item.QCQFJCD01060 == '') {
						showMsg("请输入监测点名称和监测位置");
						return;
					}
					if (item.QCQFJCD01030 == '' || item.QCQFJCD01030 == 'NO') {
						showMsg("请输选择监测类型");
						return;
					}
					showSaveProgress();
					//				item.QCQFJCD01010 = Guid();
					//					var data = {
					//						"record" : [item]
					//					};
					//					addRecords('qcqf', 'QCQFJCD01', data, function(response) {
					//						showMsg('保存成功！');
					//					}, showErro, false);
					// showMsg("saveRecord" + JSON.stringify(item));
					try {
						$.ajax({
							url : ip_req + 'ZHFZ/ZHFZService.svc/SaveQCQFJCD01',
							type : 'GET',
							dataType : 'jsonp',
							data : {
								parameters : JSON.stringify(item),
							}
						}).done(function(res) {
							api.hideProgress();
							showMsg('保存成功！');
						}).fail(function(error) {
							api.hideProgress();
							showMsg("fail" + JSON.stringify(error));
						});
					} catch(error) {
						api.hideProgress();
						// showMsg("catch" + JSON.stringify(error));
					}
				});
			}
		</script>
	</body>
</html>